package com.javasm.bootdemo.login.controller;


import com.javasm.bootdemo.common.R;
import com.javasm.bootdemo.common.exception.JavasmException;
import com.javasm.bootdemo.common.exception.JavasmExceptionEnum;
import com.javasm.bootdemo.login.service.LoginService;
import com.javasm.bootdemo.user.entity.WebUser;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    LoginService  loginService;
    @PostMapping("/doLogin")
    public R doLogin(String uname, String pwd) {
        if (StringUtils.isEmpty(uname) || StringUtils.isEmpty(pwd)) {
            throw new JavasmException(JavasmExceptionEnum.DeleteError);
        }
        //写业务逻辑，根据用户名和密码，采用很好的信息

        WebUser  webUser = loginService.loadByUname(uname,pwd);
        return  R.ok(webUser);
    }
}
